/**
 * 消息提示框
 * @author mayonghua
 * @param config
 * @return
 */
var Msg = function(config){
	this.title = config.title==null?"提示":config.title;
	this.content = config.content==null?"":config.content;
	this.type = config.type;
	this.handler = config.handler;
	this.width= config.width==null?'230':config.width;
	this.height = config.height==null?'72':config.height;
	this.init();
}
Msg.prototype = {
	init : function(){
		var entity = this;
		var id = entity.random();
		var msgDiv = entity.drawMsg(id);
		//添加到dom
		$(msgDiv).appendTo('body');
		//设置标题和内容
		var msgBody = [];
		   msgBody.push('<table class="msgbody">');
		   msgBody.push('<tr>');
		   msgBody.push('<td class="head"><div class="title">'+entity.title+'</div><div class="close"></div></td>');
		   msgBody.push('</tr>');
		   msgBody.push('<tr>');
		   msgBody.push('<td><div class="pic"></div><span class="content">'+entity.content+'</span></td>');
		   msgBody.push('<tr>');
		   msgBody.push('<td class="tools" align="center"><div class="button">确定</div></td>');
		   msgBody.push('</tr>');
		   msgBody.push('</table>');
		$(msgBody.join('')).appendTo($("#"+id+" .msg-mc"));	
		
		//设置宽度
		$("#"+id+" .msgbody").width(entity.width);
		//设置高度
		$("#"+id+" .msgbody").height(entity.height);
		var bodyDiv = $(document.body).get(0);
		//得到显示区域的宽度
		var clientWidth = bodyDiv.clientWidth;
		//得到显示区域高度
		var clientHeight = bodyDiv.clientHeight;
		var left = ($(document.body).width())/2-$("#"+id).width()/2;
		var top = ($(document.body).height())/2-$("#"+id).height()/2;
		$("#"+id).css({left:left+"px",top:top+"px"});

		//添加按钮点击事件
		$("#"+id+" .button").mouseover(function(){
			$(this).removeClass("button");
			$(this).addClass("button_hover");
		}).mouseout(function(){
			$(this).removeClass("button_hover");
			$(this).addClass("button");
		}).click(entity.handler);
		//添加关闭事件
		$("#"+id+" .close").click(function(){
				$("#"+id).remove();
		});
},
drawMsg:function(id){
		var entity = this;
		var item = [];
		item.push('<table class="msgPanel" id="'+id+'">');
		item.push('<tbody>');
		item.push('<tr>');
		item.push('<td class="msg-tl"></td>');
		item.push('<td class="msg-tc"></td>');
		item.push('<td class="msg-tr"></td>');
		item.push('</tr>');
		item.push('<tr>');
		item.push('<td class="msg-ml"></td>');
		item.push('<td class="msg-mc"></td>');
		item.push('<td class="msg-mr"></td>');
		item.push('</tr>');
		item.push('<tr>');
		item.push('<td class="msg-bl"></td>');
		item.push('<td class="msg-bc"></td>');
		item.push('<td class="msg-br"></td>');
		item.push('</tr>');
		item.push('</tbody>');
		item.push('</table>');
		
		return item.join('');
	},
	random : function(){
		//首先产生一个1000以内的随机数
		var r = Math.round(Math.random()*1000);
		//获得当前的日期
		var date = new Date();
		var year = date.getYear();
		var month = date.getMonth();
		var day = date.getDay();
		var hours = date.getHours();
		var minutes = date.getMinutes();
		var seconds = date.getSeconds();
		//根据日期+随机数生成一个随机ID
		return 'id_'+year+month+day+minutes+seconds+r;
	}
}